﻿using UnityEngine;
using UnityEditor;
namespace BehaviorSystem
{
    /// <summary>
    /// 选择节点
    /// </summary>
    public class SelectorNode : CompositeNode
    {

        public SelectorNode(IBehaviorAgent agent) : base(agent)
        {
        }

        public override BTNodeState HandleComposite()
        {

            if (curIndex< ChildrenNodes.Count)
            {
                BTNodeState childState = ChildrenNodes[curIndex].ExcuteNode();
                if (childState == BTNodeState.Success)
                {
                    CurState = BTNodeState.Success;
                }
                else if (childState == BTNodeState.Running)
                {
                    return CurState;
                }
                else
                {
                    
                }
            }

            if (CurState!=BTNodeState.Success&&curIndex == ChildrenNodes.Count)
            {
                CurState = BTNodeState.Failure;
            }
            curIndex++;
            return CurState;
        }
    }
}